import api from './index.js'

// 房间相关API - 全量对接后端接口
export const roomAPI = {
  // 获取房间列表（支持筛选）
  getRooms(page = 1, pageSize = 20, filters = {}) {
    return api.get('/room/list', {
      params: { page, pageSize, ...filters }
    })
  },

  // 创建房间
  createRoom(roomData) {
    return api.post('/room/create', roomData)
  },

  // 加入房间（支持密码）
  joinRoom(roomId, password = '') {
    return api.post(`/room/${roomId}/join`, { password })
  },

  // 离开房间
  leaveRoom(roomId) {
    return api.post(`/room/${roomId}/leave`)
  },

  // 获取房间详情
  getRoomInfo(roomId) {
    return api.get(`/room/${roomId}`)
  },

  // 获取房间内玩家列表
  getRoomPlayers(roomId) {
    return api.get(`/room/${roomId}/players`)
  },

  // 切换准备状态
  toggleReady(roomId, isReady) {
    return api.post(`/room/${roomId}/ready`, { isReady })
  },

  // 开始游戏（房主）
  startGame(roomId) {
    return api.post(`/room/${roomId}/start-game`)
  },

  // 踢出玩家（房主）
  kickPlayer(roomId, playerId) {
    return api.post(`/room/${roomId}/kick/${playerId}`)
  },

  // 发送房间聊天消息
  sendMessage(roomId, message, messageType = 'text') {
    return api.post(`/room/${roomId}/chat/send`, { message, messageType })
  },

  // 获取房间聊天历史
  getChatHistory(roomId, limit = 50, offset = 0) {
    return api.get(`/room/${roomId}/chat/history`, {
      params: { limit, offset }
    })
  },

  // 更新房间设置（房主权限）
  updateRoomSettings(roomId, settings) {
    return api.put(`/room/${roomId}/settings`, settings)
  },

  // 删除房间（房主权限）
  deleteRoom(roomId) {
    return api.delete(`/room/${roomId}`)
  },

  // 获取房间列表（性能测试场景）
  getManyRooms(page = 1, pageSize = 100) {
    return api.get('/room/list', {
      params: { page, pageSize }
    })
  }
}

